/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package assignment1;

import java.io.*;
import java.util.StringTokenizer;

/**
 *
 * @author cjaramillo
 */
public class Consequent {
    public enum Action{MOVE_FORWARD, MOVE_BACKWARD, ROTATE_CLOCKWISE, ROTATE_COUNTERCLOCKWISE, ORIENT_ROVER_TOWARD_TARGET, FOLLOW_PATH_TO_TARGET, CREATE_SUBGOAL_LIST, REMOVE_OBSTACLES_FROM_SUBGOALS, REMOVE_POSITION_FROM_SUBGOALS, FOLLOW_PATH_TO_SUBGOAL, ADD_SUBGOALS};
    private Action m_action;
            
    public void setConsequentFromUserInput()throws IOException
    {
        this.displayActionChoices();
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Integer selection = new Integer(br.readLine());
        m_action = Action.values()[selection.intValue()];
    }
    
    public void populateFromString(String consequent)
    {
        if(consequent.equals(" Move Forward"))
        {
            this.action(Action.MOVE_FORWARD);
        }
        else if(consequent.equals(" Move Backward"))
        {
            this.action(Action.MOVE_BACKWARD);
        }
        else if(consequent.equals(" Rotate Clockwise"))
        {
            this.action(Action.ROTATE_CLOCKWISE);
        }
        else if(consequent.equals(" Rotate Counterclockwise"))
        {
            this.action(Action.ROTATE_COUNTERCLOCKWISE);
        }
        else if(consequent.equals(" Orient Rover Toward Target"))
        {
            this.action(Action.ORIENT_ROVER_TOWARD_TARGET);
        }
        else if(consequent.equals(" Follow Path To Target"))
        {
            this.action(Action.FOLLOW_PATH_TO_TARGET);
        }
        else if(consequent.equalsIgnoreCase(" Create subgoal list"))
        {
            this.action(Action.CREATE_SUBGOAL_LIST);
        }
        else if(consequent.equalsIgnoreCase(" Remove obstacles from subgoals"))
        {
            this.action(Action.REMOVE_OBSTACLES_FROM_SUBGOALS);
        }
        else if(consequent.equalsIgnoreCase(" Move position to reached subgoal list"))
        {
            this.action(Action.REMOVE_POSITION_FROM_SUBGOALS);
        }
        else if(consequent.equalsIgnoreCase(" Follow Path To Subgoal"))
        {
            this.action(Action.FOLLOW_PATH_TO_SUBGOAL);
        }
        else if(consequent.equalsIgnoreCase(" Add subgoals"))
        {
            this.action(Action.ADD_SUBGOALS);
        }
        
    }
    
    private void displayActionChoices()
    {
        System.out.println("[0]: Move Forward");
        System.out.println("[1]: Move Backward");
        System.out.println("[2]: Rotate Clockwise");
        System.out.println("[3]: Rotate Counterclockwise");
        System.out.println("Please choose an action 0-3:");
    }
    
    public void action(Action action)
    {
        m_action = action;
    }
    
    public Action action()
    {
        return m_action;
    }
}
